# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=mdcat
pkgver=2.1.0
pkgrel=0
pkgdesc="Cat for markdown"
url="https://github.com/swsnr/mdcat"
#Undefined temporary symbol .LBB16_2
arch="all !armhf"
license="Apache-2.0"
makedepends="asciidoctor cargo shared-mime-info openssl-dev>3 cargo-auditable"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="https://github.com/swsnr/mdcat/archive/refs/tags/mdcat-$pkgver.tar.gz"
builddir="$srcdir/mdcat-mdcat-$pkgver"

prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/mdcat -t "$pkgdir"/usr/bin/
	ln -s /usr/bin/mdcat "$pkgdir"/usr/bin/mdless

	# Install the generated shell completion files
	install -Dm644 target/release/build/mdcat-*/out/completions/mdcat.bash \
		"$pkgdir"/usr/share/bash-completion/completions/mdcat
	install -Dm644 target/release/build/mdcat-*/out/completions/mdless.bash \
		"$pkgdir"/usr/share/bash-completion/completions/mdless
	install -Dm644 target/release/build/mdcat-*/out/completions/_mdcat \
		-t "$pkgdir"/usr/share/zsh/site-functions
	install -Dm644 target/release/build/mdcat-*/out/completions/_mdless \
		-t "$pkgdir"/usr/share/zsh/site-functions
	install -Dm644 target/release/build/mdcat-*/out/completions/mdcat.fish \
		-t "$pkgdir"/usr/share/fish/vendor_completions.d
	install -Dm644 target/release/build/mdcat-*/out/completions/mdless.fish \
		-t "$pkgdir"/usr/share/fish/vendor_completions.d

	# Install the generated man-page
	install -Dm644 "$builddir"/target/release/build/mdcat-*/out/mdcat.1 \
		-t "$pkgdir"/usr/share/man/man1/
}

sha512sums="
87d3ff136c36b4f96cc980ea3541c4e7c68d40c4061fdf4fda1bbf9838379c5fcc11f621c37de7605399e2e3d1c4ed83663acbfa0c5f39445acd2a903bedb7b9  mdcat-2.1.0.tar.gz
"
